﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace ListItTaxi.Web
{
    using KeyValue = KeyValuePair<string, string>;

    public class JSONObject
    {
        private List<KeyValue> _dict = new List<KeyValue>();
        private string _funcName;

        public JSONObject(string funcName)
        {
            _funcName = funcName;
        }

        public void add(string key, string value)
        {
            KeyValue kv = new KeyValue(key, value);

            _dict.Add(kv);
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(string.Format("{{\"{0}\":", _funcName));
            sb.Append("{");
           
            for (int i = 0; i < _dict.Count; i++) {
                sb.Append(string.Format("\"{0}\":\"{1}\"{2}", 
                    _dict[i].Key, _dict[i].Value,
                    i == _dict.Count-1 ? "" : "," ));
            }
            
            sb.Append("}}");
            return sb.ToString();
        }
    }
}